import pymysql
import json
import utils

class dbHelper():
    def __init__(self, *args, **kwargs):
        pass
    
    def __getConnection(self):
        return pymysql.connect(host="localhost",user='root',password='123456',db='ry',charset='utf8')

    def getMenus(self):
        cursor=self.__getConnection().cursor(cursor=pymysql.cursors.DictCursor)
        cursor.execute('SET CHARACTER SET utf8;')
        cursor.execute('SET character_set_connection=utf8;')
        cursor.execute(query="select * from sys_menu")
        data=cursor.fetchall()
        return json.dumps(data,cls=utils.DateEncoder)


if __name__ =="__main__":
    dbHelper=dbHelper()
    data=json.loads(str(dbHelper.getMenus()).encode('utf-8').decode('unicode_escape'))
    for d in data:
        print(d)



            
